package com.football.spwntr;

import java.io.Console;
import java.io.PrintStream;
import java.util.List;

/**
 * Created by thoughtworker on 1/16/14.
 */
public class FootballApp {
    private ConsolePrinter consolePrinter;
    private List<Participant> participantList;

    public FootballApp(ConsolePrinter consolePrinter, List<Participant> participantList) {
        this.consolePrinter = consolePrinter;
        this.participantList = participantList;
    }

    public static void main(String[] args) {
        FootballApp footballApp = new FootballApp(new ConsolePrinter(System.out), new PopulateParticipantList().returnParticipantList());
        footballApp.printAllParticipantsInformation();
    }

    public void printAPlayersInformation(Participant participant) {
        consolePrinter.print(participant.toString());
    }

    public Player findPlayer(String name, int number) {
        for (Participant participant : participantList) {
            if (participant.getClass() == Player.class && name.equals(participant.getName())) {
                Player player = (Player) participant;
                if (number == player.getNumber()) {
                    return player;
                }
            }
        }
        return null;
    }

    public void printAllParticipantsInformation() {
        for(Participant participant : participantList) {
            printAPlayersInformation(participant);
        }
    }
}
